package top.rainbowecho.gateway.exception;

import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.rainbowecho.common.exception.BlogException;
import top.rainbowecho.common.util.ResultKey;

import java.util.Map;

/**
 * @author rainbow
 * @since 2020/1/26 11:32
 */
@RestControllerAdvice
@Slf4j
public class ApplicationExceptionHandler {

    @ExceptionHandler
    public ResponseEntity<Map<String, Object>> blogExceptionHandle(BlogException e) {
        return new ResponseEntity<>(ImmutableMap.of(ResultKey.EXCEPTION_MESS, e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
    }

}
